package com.xzy.aaa.postprocessor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 创建一个实现BeanPostProcessor接口的类，用于在Bean初始化过程中对Bean进行处理
 *
 * @author xzy.xiao
 * @date 2023/7/4  19:37
 */
@Slf4j
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        // 在Bean初始化之前对其进行定制和增强，如修改Bean的属性、校验Bean的状态等
        log.info("Post process before initialization: Bean Name - {}", beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        // 在Bean初始化之后对其进行定制和增强，如添加额外的代理逻辑、修改Bean的状态等
        log.info("Post process after initialization: Bean Name - {}", beanName);
        return bean;
    }
}
